package com.example.yiparkapplication.activity.index.activity.contactUs;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.yiparkapplication.R;

import java.util.List;

public class ContactUsAdapter extends RecyclerView.Adapter<ContactUsAdapter.ViewHolder> {

    private List<String> mPictureUriList;
    private ContactUsActivity mContactActivity;

    public static class ViewHolder extends RecyclerView.ViewHolder{
        View contactUsImgView;
        ImageView picture;

        public ViewHolder(View view){
            super(view);
            contactUsImgView = view;
            picture = view.findViewById(R.id.id_contact_us_img);
        }
    }

    public ContactUsAdapter(List<String> pictureUriList, ContactUsActivity contactUsActivity){
        mPictureUriList = pictureUriList;
        mContactActivity = contactUsActivity;
    }

    @Override
    public ContactUsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_contact_us_img_layout, parent, false);
        final ContactUsAdapter.ViewHolder holder = new ContactUsAdapter.ViewHolder(view);
        holder.contactUsImgView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                int position = holder.getAdapterPosition();
                mPictureUriList.remove(position);
                mContactActivity.showImg(mPictureUriList);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ContactUsAdapter.ViewHolder holder, int position){
        String pictureUri = mPictureUriList.get(position);
        holder.picture.setImageURI(Uri.parse(pictureUri));
    }

    @Override
    public int getItemCount(){
        return mPictureUriList.size();
    }
}
